<div class="admin_nrtop">
    <div class="ad_search">
        <form action="/admini/task/index/"  method="get" style="margin:0px" id="form1">
        <div class="search">
            <div class="soubox">
                <input type="text" id="name" name="name" value="<?php echo $this->name?$this->name:"";?>" placeholder="输入任务内容"/>
                <input type="hidden" id="typeid" name="typeid" value="<?php echo $this->typeid?$this->typeid:"";?>" />
                <input type="hidden" id="status" name="status" value="<?php echo $this->status?$this->status:"";?>"/>
            </div>
            <a href="javascript:$('#form1').submit();"><span>搜索</span></a>
        </div>
        </form>
    </div>
</div>
<div  class="biaoge">
    <div class="biaotbody">
        <table>
            <tr>
                <th class="li3">
                    <div class="lileft">&nbsp;</div>
                </th>
                <th class="li20">
                    <div class="lileft"><span>任务内容</span></div>
                </th>
                <th class="li5">
                    <div class="lileft"><span>编码</span></div>
                </th>
                <th class="li8">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>任务类型</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;">
                            <ul>
                                <?php if($this->typeAll){ foreach ($this->typeAll as $typeKey => $typeVal) { ?>
                                    <li><a href="javascript:settype(<?php echo $typeKey; ?>)"><?php echo $typeVal; ?></a></li>
                                <?php }} ?>
                            </ul>
                        </div>
                    </div>
                </th>
                <th class="li8">
                    <div class="lileft"><span>完成积分</span></div>
                </th>
                <th class="li8">
                    <div class="lileft"><span>完成人数</span></div>
                </th>
                <th class="li5">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>状态</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;">
                            <ul>
                                <?php if($this->statusAll){ foreach ($this->statusAll as $statusKey => $statusVal) { ?>
                                    <li><a href="javascript:setstatus(<?php echo $statusKey; ?>)"><?php echo $statusVal; ?></a></li>
                                <?php }} ?>
                            </ul>
                        </div>
                    </div>
                </th>
                <th class="li8">
                    <div class="lileft"><span>添加人</span></div>
                </th>
                <th class="li8">
                    <div class="lileft"><span>创建时间</span></div>
                </th>
                <th class="li5">
                    <div class="lileft"><span>操作</span></div>
                </th>
            </tr>
        </table>
    </div>
    <?php if($this->typeid || ($this->status !== "" && $this->status !== null)){?>
              <div class="xzinfo">
            	<ul>
                    <?php if($this->typeid){ ?><li><div class="xzinfobox"><span><?php echo $this->typeAll[$this->typeid];?></span><a href="javascript:removeset('typeid')" title="撤销"><i>撤销</i></a></div></li><?php }?>
                    <?php if($this->status === "" && $this->status !== null){}else{ ?><li><div class="xzinfobox"><span><?php echo $this->statusAll[$this->status];?></span><a href="javascript:removeset('status')" title="撤销"><i>撤销</i></a></div></li><?php }?>
                </ul>
            </div>
     <?php }?>
     <div class="table">
         <table>
             <?php  if($this->taskList){
                foreach ($this->taskList as $Item) { ?> 
                 <tr id="tr_<?php echo $Item->id;?>">
                     <td class="li3">&nbsp;</td>
                     <td class="li20">
                         <div class="lileft">
                             <a class="indexa" href="javascript:editTask(<?php echo $Item->Id;?>)"><?php echo $Item->Name;?></a>
                         </div>
                     </td>
                     <td class="li5">
                         <div class="lileft">
                             <?php echo $Item->Code;?>
                         </div>
                     </td>
                     <td class="li8">
                         <div class="lileft yonghu">
                             <?php echo $Item->TypeName;?>
                        </div>
                     </td>
                     <td class="li8">
                         <div class="lileft">
                             <?php echo $Item->Score;?>
                        </div>
                     </td>
                     <td class="li8">
                         <div class="lileft">
                             <?php echo $Item->CompleteNum>0?"<a href='/admini/task/completeuser/taskid/".$Item->Id."' class='indexa'>".$Item->CompleteNum."</a>":$Item->CompleteNum;?>
                        </div>
                     </td>
                     <td class="li5">
                         <div class="lileft">
                             <?php echo $Item->StatusName;?>
                        </div>
                     </td>
                     <td class="li8">
                         <div class="lileft">
                             <?php echo $Item->Operator;?>
                        </div>
                     </td>
                     <td class="li8">
                         <div class="lileft">
                             <?php echo $Item->DateCreated;?>
                        </div>
                     </td>                     
                     <td class="li5">
                         <div class="lixlnav">
                             <a class="xlnavxq" href="javascript:void(0)" name="<?php echo $Item->Id;?>">编辑</a>
                             <div class="xlnavlistbox">
                                 <a class="xlnavsj" href="javascript:void(0);"><i></i></a>
                                 <div class="xlnavlist" style="display:none;">
                                     <ul>
                                        <li><a href="javascript:void(0)" name="<?php echo $Item->Id;?>" class="del_task" >删除</a></li>
                                     </ul>
                                 </div>
                             </div>
                         </div>
                     </td>
                 </tr>
             <?php } }  if(!$this->taskList){
                echo "<font size='4' color='red'>暂无数据</font>";
                }?>   
         </table>
     </div>
 </div>
<div class="toolbar">
    <div class="qunx">
        <ul>
            <li><a class="anvbotton" href="javascript:void(0)" id="addtask" name="addtask"><span>添加任务</span></a></li>
        </ul>
    </div>
<?php
    echo $this->partial('paging.phtml', array("pages" => $this->taskAll,"pamas"=>"name=$this->name&typeid=$this->typeid&status=$this->status"));        
?>
</div>
<style>
    #add_table{
        width: 540px;
        font-size: 16px;
        padding: 5px;
    }
    #add_table *{
        font-size: 14px;
        padding: 5px;
    }
</style>
<div class="tanchuang" style="display:none;">
    <div class="nui-msgbox">
        <div class="nui-msgbox-hd" id="wayProblem">添加任务</div>
        <a class="nui-msgbox-close" title="关闭"><b></b></a>
    </div>
    <div class="wenti_box" id="problemComm">
            <div style="margin-left:10px;margin-top: 15px;margin-bottom: 5px;">
                <table id="add_table">
                    <tr>
                        <td align="center" colspan="4" style="font-size:18px" class="taskTitle">添加任务</td>
                    </tr>
                    <tr>
                        <td align="right">任务内容：</td>
                        <td colspan="3"><textarea id="taskName" name="taskName" style="margin: 0px;height: 80px;width: 310px;"></textarea></td>
                    </tr>
                    <tr>
                        <td align="right">完成积分：</td>
                        <td><input type="text" id="score" name="score" value="" style="width:100px;"/></td>
                        <td align="right">编码：</td>
                        <td><input type="text" id="code" name="code" value="" style="width:100px;"/></td>
                    </tr>
                    <tr>
                        <td align="right">类型：</td>
                        <td><select id="type" name="type">
                                <?php foreach ($this->typeAll as $key=> $typeVal) { ?>
                                <option value="<?php echo $key;?>"><?php echo $typeVal;?></option>
                                <?php } ?>
                            </select></td>
                        <td align="right">状态：</td>
                        <td><select id="status" name="status">
                                <?php foreach ($this->statusAll as $key => $statusVal){?>
                                <option value="<?php echo $key;?>"><?php echo $statusVal;?></option>
                                <?php } ?>
                            </select></td>
                    </tr>
                    <tr>
                        <td align="center"  colspan="4">
                            <input type="hidden" id="taskId" name="taskId" value="" />
                            <input type="button" id="taskAdd" name="taskAdd" value="添加" style="background-color: #F60;width: 50px;height: 36px;color: white;font-size: 16px;border-radius:8px;"/>
                            &nbsp;&nbsp;<input type="button" id="refo" naem="refo" value="返回" style="background-color: #1668A4;width: 50px;height: 36px;color: white;font-size: 16px;border-radius:8px;"/>
                        </td>
                    </tr>
                </table>
            </div>
    </div>
</div>
<div class="houtai_overlay" style="display:none;"></div>
<script>
    $(".lixiala").click(function(){
        $(".lixiala").attr("class","lixiala");
        $(".lixiala").next("div").attr("style","display:none;");
    
        $(this).attr("class","lixiala bton");
        $(this).next("div").attr("style","display:block;");
    });
    $(document).bind("click",function(e){
        var target  = $(e.target);
        if(target.closest(".biaoxiala").length == 0){
            $(".lixiala").attr("class","lixiala");
            $(".lixiala").next("div").attr("style","display:none;");
        }
    });
    function settype(type)
    {
        $("#form1 #typeid").val(type);
        $("#form1").submit();
    }
    function setstatus(status)
    {
        $("#form1 #status").val(status);
        $("#form1").submit();
    }
    function removeset(set)
    {
        $("#form1 #"+set).val("");
        $("#form1").submit();
    }
    $(".xlnavsj").live("mousemove",function(){
        $(this).next("div").show();
    });
    $(".lixlnav").mouseleave(function(){
        $(".xlnavsj").next("div").hide();
    });
    $("#addtask").click(function(){
        $(".houtai_overlay").show();
        $(".tanchuang").show();
    });
    $(".nui-msgbox-close").click(function(){
        $(".houtai_overlay").hide();
        $(".tanchuang").hide();
    })
    $(".xlnavxq").click(function(){
       var id = $(this).attr("name");
       editTask(id);
    });
    function editTask(id){
        $.post("/admini/task/taskdetail",{"id":id},function(date){
           if(date.sj == 1){
                $("#taskName").val(date.name);
                $("#score").val(date.score);
                $("#code").val(date.code);
                $("#type").find("option[value='"+date.type+"']").attr("selected",true);
                $(".tanchuang #status").find("option[value='"+date.status+"']").attr("selected",true);
                $("#taskId").val(id);
                $("#taskAdd").val("修改");
                $(".tanchuang #wayProblem").html("修改任务");
                $(".tanchuang .taskTitle").html("修改任务");
                $(".houtai_overlay").show();
                $(".tanchuang").show();
           }else{
               alert("出现未知错误，请刷新在试。");
           }
       });
    }
    $(".del_task").click(function(){
        if(confirm("您确认删除该任务？","提示信息")){ 
            var id = $(this).attr("name");
            $.post("/admini/task/deltask",{"id":id},function(date){
               if(date == 1){
                    alert("删除成功");
                    $("#tr_"+id).remove();
               }else{
                   alert("出现未知错误，请刷新在试。");
               }
           },"json");
        }
    });
    $("#refo").click(function(){
        $(".houtai_overlay").hide();
        $(".tanchuang").hide();
    });
    $("#taskAdd").click(function(){
        var name = $("#taskName").val();
        var type = $("#type").val();
        var status = $(".tanchuang #status").val();
        var score = $("#score").val();
        var id = $("#taskId").val();
        var code = $("#code").val();
        if(name == ""){
            alert("任务内容不能为空");
            return ;
        }
        if(score == ""){
            alert("完成积分不能为空");
            return ;
        }
        if(code == ""){
            alert("任务编码不能为空");
            return ;
        }
        $.post('/admini/task/addoredittask', {'id':id,'name':name,"score":score,"type":type,"status":status,"code":code}, function(sj){
             if(sj == 1){
                 alert("操作成功！");
             }else{
                 alert("出现未知错误");
             }
            location.href = "/admini/task/index/";
        }, 'json');
       
    });
</script>